package com.csp.mingyue.push.mq.producer;

import cn.hutool.core.util.IdUtil;
import com.csp.mingyue.sms.api.dto.MqMessageDto;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Kafka 生产者
 *
 * @author Strive
 * @date 2023/9/21 19:40
 */
@Component
public class KafkaProducer {

	@Resource
	private StreamBridge streamBridge;

	public void kafkaDemoMsg(String msg) {
		// 构建消息对象
		MqMessageDto messageDto = new MqMessageDto().setMsgId(IdUtil.fastSimpleUUID()).setMsgText(msg);

		streamBridge.send("kafkaDemo-out-0", MessageBuilder.withPayload(messageDto).build());
	}

}
